<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<meta http-equiv="Cache-Control" content="no-siteapp">
		<link rel="stylesheet" href="../../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../../css/public.css" media="all" />
	</head>

	<body class="childrenBody">
		<form class="layui-form" lay-filter="formTest" id="form" style="width: 80%;">
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">设备类型</label>
				<div class="layui-input-block">
					<select id="dtid" name="dtid" lay-verify="">
						<option value="">请选择</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">购买人</label>
				<div class="layui-input-block">
					<select id="buyer" name="buyer" lay-verify="">
						<option value="">请选择</option>
					</select>
				</div>

			</div>
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">购买日期</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input" id="buydate" name="buydate" lay-verify="required" placeholder="">
				</div>
			</div>

			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">文件</label>
				<div class="layui-input-block">
					<button type="button" class="layui-btn" id="file">
						<i class="layui-icon">&#xe67c;</i>选择文件
					</button>
				</div>
			</div>



			<div class="layui-form-item layui-row layui-col-xs12">
				<div class="layui-input-block">
					<button type="button" class="layui-btn layui-btn-sm" lay-submit="" id="submit" lay-filter="submit">提交</button>
					<button type="button" class="layui-btn layui-btn-sm layui-btn-primary close-btn">取消</button>
				</div>
			</div>
		</form>
		<script type="text/javascript" src="../../../js/jquery-2.1.1.min.js"></script>
		<script type="text/javascript" src="../../../layui/layui.js"></script>
		<script type="text/javascript" src="../../../custom/js/common.js"></script>
		<!-- <script type="text/javascript" src="../../../js/index.js"></script> -->
		<script type="text/javascript">
			layui.use(['form', 'laydate', 'layer','upload'], function() {
				var form = layui.form;
				var laydate = layui.laydate;
				var layer = parent.layer === undefined ? layui.layer : top.layer,
					$ = layui.jquery;
				var upload = layui.upload;
				var toUploadApi = constant.baseUrl + "/device/device/toUpload";
				var uploadApi = constant.baseUrl + "/device/device/upload";
				//上传的时候加载
				loadAjax(toUploadApi, "get", null, function(response) {
					baseCallBack(response, function(response) {
						if (response.data.devicetypes) {
							var tmp = '';
							for (var devicetype of response.data.devicetypes) {
								tmp += '<option value="' + devicetype.id + '">' + devicetype.name + '</option>';
							}
							$("#dtid").append(tmp);
						}
						if (response.data.users) {
							var tmp = '';
							for (var user of response.data.users) {
								tmp += '<option value="' + user.id + '">' + user.rname + '</option>';
							}
							$("#buyer").append(tmp);
						}
						form.render('select'); //刷新select选择框渲染
					});
				});

				//初始化日期
				laydate.render({
					elem: '#buydate'
				});

				//执行实例
				var uploadInst = upload.render({
					elem: '#file',
					url: uploadApi,
					data:{
						dtid:'',
						buyer:'',
						buydate:''
					},
					before:function(){
						this.data.dtid=$("#dtid").val(),
						this.data.buyer=$("#buyer").val(),
						this.data.buydate=$("#buydate").val()
					},
					exts:'xls|xlsx',
					accept:'file',
					auto:false,
					bindAction:'#submit',
					done: function(response) {
						//上传完毕回调
						baseCallBack(response, parentReloadCallBack);
					}
				});

			})
		</script>
	</body>

</html>
